#region Header Licence
//  NKnobMan, Copyright 2009, Alexandre MUTEL.
// 
//  This is free software; you can redistribute it and/or modify it
//  under the terms of the GNU Lesser General Public License as
//  published by the Free Software Foundation; either version 2.1 of
//  the License, or (at your option) any later version.
// 
//  This software is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//  Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public
//  License along with this software; if not, write to the Free
//  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
//  02110-1301 USA, or see the FSF site: http://www.fsf.org.
#endregion
using System.Runtime.Serialization;

namespace NKnobMan
{
    public interface AnimatedValue<T>
    {
        [DataMember]
        T From
        {
            get;
            set;
        }

        [DataMember]
        T To
        {
            get;
            set;
        }

        [DataMember]
        bool Animate
        {
            get;
            set;
        }

        int Curve
        {
            get;
            set;
        }
    }

    [DataContract]
    public class FloatAnimateLayerItem : AnimateLayerItem<float>
    {
        public FloatAnimateLayerItem(Layer layer, string propertyName, KnobManFieldAttribute knobManFieldAttribute)
            : base(layer, propertyName, knobManFieldAttribute)
        {
        }
    }

    [DataContract]
    public class IntAnimateLayerItem : AnimateLayerItem<int>
    {
        public IntAnimateLayerItem(Layer layer, string propertyName, KnobManFieldAttribute knobManFieldAttribute)
            : base(layer, propertyName, knobManFieldAttribute)
        {
        }
    }

    [DataContract]
    public class AnimateLayerItem<T> : LayerItem, AnimatedValue<T>
    {
        private KnobManFieldAttribute _knobManFieldAttribute;
        private string _propertyName;
        
        public AnimateLayerItem(Layer layer, string propertyName, KnobManFieldAttribute knobManFieldAttribute) : base(layer)
        {
            _propertyName = propertyName;
            _knobManFieldAttribute = knobManFieldAttribute;
        }


        [DataMember, KnobManField]
        public T From
        {
            get
            {
                return Layer.GetValue<T>(_propertyName + "From", _knobManFieldAttribute.FromName);
            }
            set
            {
                Layer.SetValue(_propertyName + "From", _knobManFieldAttribute.FromName, value);
            }
        }

        [DataMember, KnobManField]
        public T To
        {
            get { return Layer.GetValue<T>(_propertyName + "To", _knobManFieldAttribute.ToName); }
            set { Layer.SetValue(_propertyName + "To", _knobManFieldAttribute.ToName, value); }
        }

        [DataMember, KnobManField]
        public bool Animate
        {
            get { return Layer.GetValue<bool>(_propertyName + "Animate", _knobManFieldAttribute.AnimateName); }
            set { Layer.SetValue(_propertyName + "Animate", _knobManFieldAttribute.AnimateName, value); }
        }

        [DataMember, KnobManField]
        public int Curve
        {
            get { return Layer.GetValue<int>(_propertyName + "Curve", _knobManFieldAttribute.CurveName); }
            set { Layer.SetValue(_propertyName + "Curve", _knobManFieldAttribute.CurveName, value); }
        }
        
        public override string ToString()
        {
            return string.Format("{0}(From = [{1}], To = [{2}], Animate = [{3}]", _propertyName, From, To, Animate);
        }


    }

}
